﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TrainingsApp.Logic.Import.Template;
using TrainingsApp.Logic.Import.Model;
using TrainingsApp.Logic;
using TrainingsApp.Model;
using System.IO;
using TrainingsApp.Logic.Import;
using Microsoft.Office.Interop.Word;

namespace ImportTest {
    class Program {
        private static void Import(ChapterTemplate_1 entity, long parentId, long MaterialsId) {

            //var insertEntity = TS_TeachMaterials_Chapter_Logic.TS_TeachMaterials_Chapter_Add(new TS_TeachMaterials_Chapter_Entity {
            //    IsLeaf = entity.Children.Count == 0,
            //    MaterialsId = MaterialsId,
            //    ParentIdx = parentId,
            //    Name = entity.Name,
            //    RootPath = string.Empty

            //});
            using (FileStream str = new FileStream(@"D:\temp.txt", FileMode.Append, FileAccess.Write)) {
                using (StreamWriter writer = new StreamWriter(str)) {
                    string line = entity.Name;
                    int t = 0;
                    while (t < entity.Level) {
                        line = "\t" + line;
                        t++;
                    }
                    writer.WriteLine(line);
                }
            }

            foreach (var item in entity.Children) {
                Import(item, 0, MaterialsId);
            }
        }
        static void Main(string[] args) {

            XLS_ChapterDataReader_1 tempReader = new XLS_ChapterDataReader_1();
            var dict = tempReader.ReadAll(1, @"E:\曹磊\教育\前概念\初中科学知识点编码.xls", 0);


            foreach (var item in dict.Values) {
                ChapterTemplate_1 itemList = item as ChapterTemplate_1;
                //var insertEntity = TS_TeachMaterials_Chapter_Logic.TS_TeachMaterials_Chapter_Add(new TS_TeachMaterials_Chapter_Entity {
                //    IsLeaf = false,
                //    MaterialsId = 1,
                //    ParentIdx = 0,
                //    Name = itemList.Name,
                //    RootPath = string.Empty
                //});
                Import(itemList, 0, itemList.MetalsId);
            }


            //XLS_SchoolDataReader_1 template = new XLS_SchoolDataReader_1();
            //int allRow = 0;
            //var allData = template.ReadAll(@"E:\曹磊\教育\TrainingsApp\Doc\浙江省学校.xls", 0);
            //foreach (var item in allData.Values) {
            //    var list = item as List<SchoolTemplate_1>;
            //    foreach (var listItem in list) {
            //        Console.WriteLine(listItem.SchoolName);
            //    }
            //    allRow += list.Count;
            //}
            //    Console.WriteLine(allRow);

            //var strs = System.IO.Directory.GetFiles(@"E:\曹磊\教育\TrainingsApp\TrainingsApp.Config\Configuration\Auto");
            //foreach (var item in strs) {

            //    Console.Write(string.Format(@"<file name=""auto\{0}"" />",Path.GetFileName( item)));
            //}

            //var entity = TS_Province_Logic.TS_Province_Add(new TS_Province_Entity {
            //    ProvinceName = "asdasd",
            //    Sort = 112
            //});
            // Console.WriteLine(entity.Idx);



            //SchoolTypeImport import = new SchoolTypeImport();


            //import.Import(@"E:\曹磊\教育\TrainingsApp\Doc\浙江省学校.xls", ImportType.School);


            //Console.ReadLine();


            //var vk_word_app = new Application();

            //object fileName = @"E:\曹磊\教育\人教版初中语文知识点目录结构树.doc";
            //object vk_missing = System.Reflection.Missing.Value;
            //vk_word_app.Visible = false;
            //var vk_my_doc = vk_word_app.Documents.Open(ref fileName, ref vk_missing, ref vk_missing, ref vk_missing, ref vk_missing, ref vk_missing, ref vk_missing, ref vk_missing, ref vk_missing, ref vk_missing, ref vk_missing, ref vk_missing, ref vk_missing, ref vk_missing, ref vk_missing, ref vk_missing);
            //using (FileStream file = new FileStream(@"D:\te.txt", FileMode.Create)) {
            //    using (StreamWriter writer = new StreamWriter(file, Encoding.UTF8)) {
            //        writer.Write(vk_my_doc.Content.Text);
            //    }

            //}
            //vk_word_app.Quit();

            //Txt_ChapterDataReader_1 provider = new Txt_ChapterDataReader_1();
            //provider.ReadAll(@"D:\七年级上册.txt", 0);
            // ImportProcess.ImportChapter();

            Console.ReadLine();
        }
    }
}
